<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%--
代码为自动生成 Created by www.magicalcoder.com
 如果你改变了此类 read 请将此行删除
 欢迎加入官方QQ群:323237052
--%>
<html>
<head>
    <%@include file="../../common/head.jsp"%>
    <title>AdminLTE | Dashboard</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <%@include file="../include/head.jsp"%>
</head>
<body class="skin-blue">
    <header class="header">
        <%@include file="../include/top.jsp"%>
    </header>
    <div class="wrapper row-offcanvas row-offcanvas-left" id="formArea">
        <aside class="left-side sidebar-offcanvas">
            <%@include file="../include/left.jsp"%>
        </aside>
        <aside class="right-side">
            <section class="content-header">
                <h1>
                    班级详情
                    <small></small>
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li><a href="#">Tables</a></li>
                    <li class="active">Data tables</li>
                </ol>
            </section>
            <section class="content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="box box-primary">
                            <form class="form-horizontal" role="form" id="form" action="admin/classes/save" method="post">
                                <div class="box-header">
                                    <h3 class="box-title">
                                        <c:choose><c:when test="${classes.id==null}">新增</c:when><c:otherwise>编辑</c:otherwise></c:choose>
                                    </h3>
                                    <h3 class="box-title alert-danger">${exceptionMsg}</h3>
                                </div>
                                    <input type="hidden" name="id" value="${classes.id}">

                                <div class="box-body">
                                    <div class="form-group ">
                                        <label class="col-sm-1 control-label">
                                            班级名称
                                        </label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control " 
                                                   name="className" title="班级名称"  placeholder="请输入班级名称"
                                                   minLength="0"            value="${classes.className}">
                                        </div>
                                        <label class="col-sm-2 control-label" >
                                            <span class="validateMsg"></span>
                                        </label>
                                    </div>
                                    <div class="form-group ">
                                        <label class="col-sm-1 control-label">
                                            班级学生人数1
                                        </label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control " 
                                                   name="studentCount" title="班级学生人数1"  placeholder="请输入班级学生人数"
                                                   minLength="0"            value="${classes.studentCount}">
                                        </div>
                                        <label class="col-sm-2 control-label" >
                                            <span class="validateMsg"></span>
                                        </label>
                                    </div>
                                    <div class="form-group ">
                                        <label class="col-sm-1 control-label">
                                            学校id
                                        </label>
                                         <div class="col-sm-3 input-select">
                                            <input type="hidden" name="schoolId" value="${classes.schoolId}" foreignTableName="school" foreignJavaField="id" selectValue="">
                                            <input type="text" class="form-control" name="schoolIdSearch"
            placeholder="搜索一下">
                                        </div>
                                        <label class="col-sm-2 control-label" >
                                                <c:if test="${ classes.schoolId!=null}">
                                                    <a target="_blank" onclick="openUrl(this,'admin/school/detail_param?id=${classes.schoolId}')"> 查看详情</a>
                                                </c:if>
                                            <span class="validateMsg"></span>
                                        </label>
                                    </div>
                                </div><!-- /.box-body -->
                                <div class="box-footer">
                                    <button type="button" onclick="submitForm2('#formArea','#form',realSubmit)" class="btn btn-primary">保存</button>
                                    <button type="button" onclick="history.go(-1);"  class="btn btn-primary">返回</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </section>

            <section class="content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs">
                                    <li class="active" ><a href="#classTeacherTab" data-toggle="tab" aria-expanded="true">班级关联教师</a></li>

                                    <li  ><a href="#studentTab" data-toggle="tab" aria-expanded="true">学生</a></li>

                            </ul>
                            <div class="tab-content">
                                    <div class="tab-pane active" id="classTeacherTab">
                                        <div class="box">
                                            <div class="box-header"></div>
                                            <div class="box-header">
                                                <div class="form-horizontal" >
                                                    <div class="col-sm-1">
                                                        <input type="button" onclick="batchDeleteItem('classTeacher')" value="删除选中项">
                                                    </div>
                                                    <div class="col-sm-1">
                                                        <input type="button" onclick="insertNewTr('classTeacher')" value="新增">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="box-body">
                                                <table class="table table-bordered table-hover dataTable">
                                                    <thead>
                                                    <tr>
                                                        <th><input type="checkbox"></th>


                                                                <th>老师表主键</th>

                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    <c:forEach var="classTeacher" items="${classTeacherList}">
                                                        <%@include file="classTeacherTr.jsp"%>
                                                    </c:forEach>
                                                    </tbody>
                                                    <tfoot></tfoot>
                                                </table>
                                            </div>
                                            <div class="box-footer">
                                                <div class="col-xs-6">
                                                    <div class="dataTables_info"></div>
                                                </div>
                                                <div class="col-xs-6">
                                                    <div class="dataTables_paginate paging_bootstrap">
                                                        <ul class="pagination" id="classTeacherPagination">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="tab-pane " id="studentTab">
                                        <div class="box">
                                            <div class="box-header"></div>
                                            <div class="box-header">
                                                <div class="form-horizontal" >
                                                    <div class="col-sm-1">
                                                        <input type="button" onclick="batchDeleteItem('student')" value="删除选中项">
                                                    </div>
                                                    <div class="col-sm-1">
                                                        <input type="button" onclick="insertNewTr('student')" value="新增">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="box-body">
                                                <table class="table table-bordered table-hover dataTable">
                                                    <thead>
                                                    <tr>
                                                        <th><input type="checkbox"></th>

                                                                <th>性别</th>

                                                                <th>学生名称</th>


                                                                <th>管理员</th>

                                                                <th>创建时间</th>

                                                                <th>更新时间</th>

                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    <c:forEach var="student" items="${studentList}">
                                                        <%@include file="studentTr.jsp"%>
                                                    </c:forEach>
                                                    </tbody>
                                                    <tfoot></tfoot>
                                                </table>
                                            </div>
                                            <div class="box-footer">
                                                <div class="col-xs-6">
                                                    <div class="dataTables_info"></div>
                                                </div>
                                                <div class="col-xs-6">
                                                    <div class="dataTables_paginate paging_bootstrap">
                                                        <ul class="pagination" id="studentPagination">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

        </aside>
    </div>

    <div class="hidden">
        <table>
            <tbody id="classTeacherTbody">
            <%@include file="classTeacherTr.jsp"%>
            </tbody>
        </table>
        <table>
            <tbody id="studentTbody">
            <%@include file="studentTr.jsp"%>
            </tbody>
        </table>
    </div>
    <%@include file="../include/tail.jsp"%>

    <script type="text/javascript" >
        $(function(){
            //base.js
            validateForm2($("#formArea"))
            //inputSelect
            inputSelectSetValue();
            $("section").find(".input-select").each(function(index,item){
                registerInputSelect($(item));
            })
        })
        function realSubmit(){
            var form = $("#form")
            var classes = findFormData(form)
                classes.date = new Date().getTime()
                $.post("admin/classes/ajax_save",classes,function(data){
                    if(data.code != 0){
                        alert(data.message)
                    }else {
                        var relateId = data.info

                        var classTeacherList = tableDataList($("#classTeacherTab"));
                        var classTeacherJson = JSON.stringify(classTeacherList)
                        $.post("admin/class_teacher/batch_save",{date:new Date().getTime(),"saveJson":classTeacherJson,"classId":relateId},function(data){
                            if(data.code != 0){
                                alert(data.message)
                            }
                        })

                        var studentList = tableDataList($("#studentTab"));
                        var studentJson = JSON.stringify(studentList)
                        $.post("admin/student/batch_save",{date:new Date().getTime(),"saveJson":studentJson,"classId":relateId},function(data){
                            if(data.code != 0){
                                alert(data.message)
                            }
                        })
                        alert("保存完毕")
                    }
            })
        }
    </script>
</body>
</html>
